<template>
  <contentModel v-if="editModelShow" :title="'编辑'" @close="handleClose">
    <a-form
      ref="formRef"
      :model="siderForm"
      auto-label-width
      @submit="handleSubmit"
    >
      <a-row :gutter="8">
        <a-col :span="12">
          <a-form-item field="techConditionVersion" label="技术条件版次">
            <a-input
              v-model="siderForm.techConditionVersion"
              placeholder="请输入"
            />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item field="outFactoryLossQty" label="厂外消耗数量(采购)">
            <a-input
              v-model="siderForm.outFactoryLossQty"
              placeholder="请输入"
            />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="8">
        <a-col :span="12">
          <a-form-item field="inFactoryLossQty" label="厂内消耗数量(库存)">
            <a-input
              v-model="siderForm.inFactoryLossQty"
              placeholder="请输入"
            />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item field="physicochemicalQty" label="理化件(库存)">
            <a-input
              v-model="siderForm.physicochemicalQty"
              placeholder="请输入"
            />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="8">
        <a-col :span="12">
          <a-form-item field="pmsReceiveSize" label="到货尺寸">
            <a-input v-model="siderForm.pmsReceiveSize" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item field="reviewCheckSpecs" label="入厂复验规范">
            <a-input
              v-model="siderForm.reviewCheckSpecs"
              placeholder="请输入"
            />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="8">
        <a-col :span="12">
          <a-form-item field="weight" label="重量">
            <a-input v-model="siderForm.weight" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item field="weightUnit" label="重量单位">
            <a-input v-model="siderForm.weightUnit" placeholder="请输入" />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="8">
        <a-col :span="12">
          <a-form-item field="checkLossQty" label="消耗数量">
            <a-input v-model="siderForm.checkLossQty" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item field="secretPeriod" label="保密期限">
            <a-input v-model="siderForm.secretPeriod" placeholder="请输入" />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="8">
        <a-col :span="12">
          <a-form-item field="materialSecretLevel" label="实物密级">
            <secretLevelSelect
              v-model="siderForm.materialSecretLevel"
              allow-clear
              dict-type="materialSecretLevel"
              :secret-level="secretLevel"
              placeholder="请选择"
            ></secretLevelSelect>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item field="pickupTotalFlag" label="齐套标志">
            <dict-select
              v-model="siderForm.pickupTotalFlag"
              allow-clear
              dict-type="pickupTotalFlag"
              placeholder="请选择"
            ></dict-select>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="8">
        <a-col :span="12">
          <a-form-item field="urgencyDegree" label="紧急程度">
            <dict-select
              v-model="siderForm.urgencyDegree"
              allow-clear
              dict-type="urgencyDegree"
              placeholder="请选择"
            ></dict-select>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item field="isHaveCredentials" label="是否带证">
            <dict-select
              v-model="siderForm.isHaveCredentials"
              allow-clear
              dict-type="YN"
              placeholder="请选择"
            ></dict-select>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="8">
        <a-col :span="12">
          <a-form-item field="recheckDate" label="复验期">
            <a-date-picker v-model="siderForm.recheckDate" />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item field="sealDate" label="油封期">
            <a-date-picker v-model="siderForm.sealDate" />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="8">
        <a-col :span="12">
          <a-form-item field="itemState" label="成品状态">
            <dict-select
              v-model="siderForm.itemState"
              allow-clear
              dict-type="itemState"
              placeholder="请选择"
            ></dict-select>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item field="arrivalDate" label="到货日期">
            <a-date-picker v-model="siderForm.arrivalDate" />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="8">
        <a-col :span="12">
          <a-form-item field="maxStorageDate" label="最长保管期">
            <a-date-picker v-model="siderForm.maxStorageDate" />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item field="validateDate" label="有效保管期">
            <a-date-picker v-model="siderForm.validateDate" />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="8">
        <a-col :span="12">
          <a-form-item field="acceptanceDate" label="验收日期">
            <a-date-picker v-model="siderForm.acceptanceDate" />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item field="archiveDate" label="封存日期">
            <a-date-picker v-model="siderForm.archiveDate" />
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
    <div style="margin: 16px; text-align: right">
      <a-button type="primary" @click="handleSubmit">保存</a-button>
    </div>
  </contentModel>
</template>

<script lang="ts" setup>
  import dictSelect from '@/common/components/dict-select/index.vue';
  import secretLevelSelect from '@/common/components/cac-components/secret-level-select/index.vue';
  import { defineAsyncComponent, ref } from 'vue';
  import { updateReceiveCheck } from '@/api/admission/typeConfirmation';
  import { Message } from '@arco-design/web-vue';

  const contentModel = defineAsyncComponent(
    () => import('@/common/components/content-model/index.vue')
  );
  const formRef = ref();
  const secretLevel = ref(null);
  defineProps({
    editModelShow: { type: Boolean, default: false },
  });
  const emit = defineEmits(['update:editModelShow', 'refresh']);
  // const emit = defineEmits(['handleClose']);
  // const siderForm = computed(() => {
  //   return props.formData;
  // });
  const init = (val) => {
    secretLevel.value = val.materialSecretLevel;
    siderForm.value = val;
  };
  const siderForm = ref({
    techConditionVersion: '',
    outFactoryLossQty: '',
    inFactoryLossQty: '',
    physicochemicalQty: '',
    pmsReceiveSize: '',
    reviewCheckSpecs: '',
    weight: '',
    weightUnit: '',
    checkLossQty: '',
    secretPeriod: '',
    materialSecretLevel: '',
    pickupTotalFlag: '',
    urgencyDegree: '',
    isHaveCredentials: '',
    recheckDate: '',
    sealDate: '',
    itemState: '',
    arrivalDate: '',
    maxStorageDate: '',
    validateDate: '',
    acceptanceDate: '',
    archiveDate: '',
  });
  const handleClose = () => {
    emit('update:editModelShow', false);
  };

  const handleSubmit = async () => {
    const { data } = await updateReceiveCheck(siderForm.value);
    if (data) {
      Message.success('修改成功');
      handleClose();
      emit('refresh');
    }
  };
  defineExpose({ init });
</script>

<style lang="less" scoped>
  /deep/ .arco-picker {
    width: 100%;
  }

  .view-background {
    padding: 16px;
    background: #f7f9fc;
  }
</style>
